import * as XLSX from "xlsx"

/**
 * 导出文件xlsx
 * @param headers 导出文件表格名
 * @param exportData 导出文件数据
 * @param fileName 导出文件名
 */
export const useXlsxDownload = (
    headers: any,
    exportData: any,
    fileName: string
) => {
    const workSheet = XLSX.utils.json_to_sheet(exportData)
    const workbook = XLSX.utils.book_new()
    // 设置表头的中文名称
    headers.forEach((header: string, index: number) => {
        const cellAddress = String.fromCharCode(65 + index) + "1";
        workSheet[cellAddress] = { t: "s", v: header };
    });
    XLSX.utils.book_append_sheet(workbook, workSheet, "导出信息")
    XLSX.writeFile(workbook, `${fileName}.xlsx`)
    ElMessage.success('导出成功')
}
